﻿using DataCenter.Entitys;
using DataCenter.IRepository;
using DataCenter.Service.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataCenter.Service.Implementations
{
    public class CustomerService : ICustomerService
    {
        private readonly ICustomerRepository customerRepository;
        public CustomerService(ICustomerRepository repository)
        {
            customerRepository=repository;
        }
        public async Task<int> Add(Customer customer)
        {
            var  item=await customerRepository.GetById(customer.Id);
            if (item != null)
            {
                throw new InvalidDataException("该数据已经存在");
            }
           return await customerRepository.Add(customer);
        }

        public async Task<int> Delete(Guid id)
        {
            return await customerRepository.DeleteById(id);
        }

        public async Task<IEnumerable<Customer>> GetAll()
        {
            return await customerRepository.GetAll();
        }

        public async Task<Customer> GetById(Guid id)
        {
            return await customerRepository.GetById(id);
        }

        public async Task<int> Update(Customer customer)
        {
            return await customerRepository.Update(customer);
        }
    }
}
